const pickerOption = {
  startDate: null
}

export const option = {
  shortcuts: [
    {
      text: '今日数据',
      onClick(picker) {
        const end = new Date()
        const start = new Date()
        picker.$emit('pick', [start, end])
        picker.$emit('change', [start, end])
      }
    },
    {
      text: '近一周',
      onClick(picker) {
        const end = new Date()
        const start = new Date()
        start.setTime(start.getTime() - 3600 * 1000 * 24 * 7)
        picker.$emit('pick', [start, end])
        picker.$emit('change', [start, end])
      }
    },
    {
      text: '最近一个月',
      onClick(picker) {
        const end = new Date()
        const start = new Date()
        start.setTime(start.getTime() - 3600 * 1000 * 24 * 30)
        picker.$emit('pick', [start, end])
        picker.$emit('change', [start, end])
      }
    }
  ],
  onPick({ minDate, maxDate }) {
    pickerOption.startDate = minDate
    if (maxDate) {
      pickerOption.startDate = null
    }
  },
  disabledDate(date) {
    if (pickerOption.startDate === null) {
      return false
    }
    const startTime = pickerOption.startDate.getTime()
    const maxTime = startTime + 3600 * 1000 * 24 * 30
    const minTime = startTime - 3600 * 1000 * 24 * 30

    return date.getTime() > maxTime || date.getTime() < minTime
  }
}

export const flagList = [
  { id: 0, text: '7日内' },
  { id: 1, text: '7日之前' }
]
